<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.kms.model.*" %>
<%@ page import="java.io.*" %>
<%@page import="java.text.SimpleDateFormat"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String command = "";
if(request.getAttribute("command")!=null){
	command = request.getAttribute("command")+"";
}

//下载
String basePath2 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/";
String filepath =request.getAttribute("dir")+"";
java.text.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<String[]> listnames = new ArrayList<String[]>();
try{
	java.io.File file = new java.io.File(filepath);
	File[] files = file.listFiles();
	for(File fi:files){
		if(fi.isFile()){
			listnames.add(new String[]{fi.getName(),sdf.format(fi.lastModified())});
		}else if(fi.isDirectory()){
		}
	}
}catch(Exception ex){
}

String id = request.getAttribute("id")+"";
MSyspara mssys_db=new MSyspara();
if(request.getAttribute("mssysapp")!=null){
	mssys_db = (MSyspara)request.getAttribute("mssysapp");
};
%>
<%!
public String Value (Object v)
{
	String rv = "UnKonw";
	if(v!=null){
		rv = v.toString();
	}
	return rv;
}
%>
<html><head>
<script type="text/javascript">
function statuss(num){
	document.getElementById("status1").value = num;
	var form = document.getElementById("thisform");
    form.submit();
}
</script>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
   <title>MBean Inspector</title>
   <link rel="stylesheet" href="<%=basePath %>css/style_master.css" type="text/css">
   <meta http-equiv="cache-control" content="no-cache">
</head>
<body>



<form id="thisform" method="post" action="logview">
<input id="status1" name="status1" type="hidden" />
<input id="id" name="id" value="<%=id %>" type="hidden" />
<table width="100%">
   </table><table>
      <tbody><tr>
         <td><img src="<%=basePath %>img/logo02.gif" alt="JBoss" align="left" border="0"></td>
         <td valign="middle"><h1>Log Zip View</h1></td>
      </tr><tr>
   </tr></tbody></table>
<ul>
   <table>
      <tbody>
      <li>Introduction :</li>
      <tr>
      	
         <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>This page provides run on TBS Server compressed backup log package, and provide the log package downloaded to a local function, which packaged the log directory for the log all the logs, while providing clear day functions.<b/></td>
      </tr>
   </tbody>
   </table>
</ul>   
   <ul>
   <table>
      <tbody>
      <li>Server configuration information :</li>
	     <%
	     %>
	      <tr>
	         <td>Linux Database IP:<b><%=Value(mssys_db.getOsip()) %></b></td>
	         <td>Linux SSH Port:<b><%=Value(mssys_db.getOsport()) %></b></td>
	        
	      </tr>
	
	      <tr>
		      <td>Linux SSH User:<b><%=Value(mssys_db.getOsuser()) %></b></td>
		      <td>Linux SSH Pwd:<b><%=Value(mssys_db.getOspwd()) %></b></td>
	      </tr>
	
	      <tr>
	      	<td>Linux DBBackup Directory:</td>
	      	<td><b><%=Value(mssys_db.getLogzipdir()) %></b></td>
	      </tr>
	     <%
	     
	      %>
   	  </tbody>
   </table>
</ul>
<!-- server list config start-->
<table width="524" height="49" border="1" cellpadding="1" cellspacing="1" >
	<%
	List<MGroup> listmg = new ArrayList<MGroup>();
	if(request.getAttribute("listmgroup")!=null){
		listmg = (List<MGroup>)request.getAttribute("listmgroup");
	}
	
	//--------------------------
	
	MSyspara msapp=new  MSyspara();
	MSyspara msdb = new MSyspara() ;
	List<Map>  listsys = new ArrayList<Map>();
	if(request.getAttribute("listmgroup")!=null){
		for(MGroup mg:listmg){
			Map<String,Object>	mapv = new HashMap<String,Object>();
			mapv.put("mgroup",mg);
			if(mg.getListsyspara()!=null){
				for(int j=0;j<mg.getListsyspara().size();j++){
					MSyspara ms = mg.getListsyspara().get(j);
					if("APP".equals(ms.getDatatype())){
						msapp = ms;
						mapv.put("sysapp",ms);
					}else{
						msdb = ms;
						mapv.put("sysdb",ms);
					}	
				}
			}
			listsys.add(mapv);
		}
	}
	
	
	MSyspara mssysapp = new MSyspara();
	MSyspara mssysdb = new MSyspara();
	MSyspara mssysapp2 = new MSyspara();
	MSyspara mssysdb2 = new MSyspara();
	MGroup mgroup = new MGroup();
	MGroup mgroup2 = new MGroup();
	for(int i=0;i<listsys.size();){
		Map mapmsyspara = listsys.get(i);
		Map mapmsyspara2 = (i+1)>=listsys.size()?null:listsys.get(i+1);
		
		if(mapmsyspara!=null ){
			if(mapmsyspara.get("mgroup")!=null){
				mgroup = (MGroup)mapmsyspara.get("mgroup");
			}
			if(mapmsyspara.get("sysapp")!=null ){
				mssysapp = (MSyspara)mapmsyspara.get("sysapp");
			}
			if(mapmsyspara.get("sysdb")!=null ){
				mssysdb = (MSyspara)mapmsyspara.get("sysdb");
			}
		}
		
		if(mapmsyspara2!=null ){
			if(mapmsyspara2.get("mgroup")!=null){
				mgroup2 = (MGroup)mapmsyspara2.get("mgroup");
			}
			if(mapmsyspara2.get("sysapp")!=null ){
				mssysapp2 = (MSyspara)mapmsyspara2.get("sysapp");
			}
			if(mapmsyspara2.get("sysdb")!=null ){
				mssysdb2 = (MSyspara)mapmsyspara2.get("sysdb");
			}
		}
		
		
		%>
	  <tr>
	    <td width="51" rowspan="2"><%=(mgroup).getName() %></td>
	    <td width="72" bgcolor="#CCCCCC">
	    	<a href="<%=basePath %>logview?id=<%=(mgroup).getId() %> " >
	    		<%=(mssysapp).getDatatype() %>
	    	</a>
	    </td>
	    <td width="121">
	    	<a href="<%=basePath %>logview?id=<%=(mgroup).getId() %> " >
	    		<%=(mssysapp).getOsip() %>
	    	</a>
	    </td>
	<%
	    if(mapmsyspara2!=null){
	    	%>
			    <td width="51" rowspan="2">
					    <%=(mgroup2).getName() %>
				</td>
			    <td width="60" bgcolor="#CCCCCC">
				    <a href="<%=basePath %>logview?id=<%=(mssysapp2).getId() %> " >
				    	<%=(mssysapp2).getDatatype() %>
				    </a>
			    </td>
			    <td width="136">
			    	<a href="<%=basePath %>logview?id=<%=(mssysapp2).getId() %> " >
			    		<%=(mssysapp2).getOsip() %>
			    	</a>
			    </td>
	    	<%
	    }
	%>
	
	  </tr>
	  <tr>
	    <td bgcolor="#CCCCCC">
	    		<%=(mssysdb).getDatatype() %>
	    </td>
	    <td>
	    		<%=(mssysdb).getOsip() %>
	    </td>
	<%
	    if(mapmsyspara2!=null){
	    	%>
				<td bgcolor="#CCCCCC">
		    		<%=(mssysdb2).getDatatype() %>
			    </td>
			    <td>
			    		<%=(mssysdb2).getOsip() %>
			    </td>
	    	<%
	    }
	%>
	  </tr>
		<%
		i=i+2;}
	%>
</table> 
<!-- server list config end-->
<table cellpadding="5">
   <tbody><tr>
	  <td>
      </td>
      <td><a href="<%=basePath %>/logview">Refresh MBean View</a></td>
   	  <td width="300">
   	  <input id="ziplog" name="ziplog" type="button"  value="Log Zip" onclick="javascrpt:statuss('ziplog');"/>
   	  <input id="remove" name="remove" type="button"  value="Remove Zip" onclick="javascrpt:statuss('remove');"/>
   	  </td>
   </tr>
</tbody></table>

<h3>DBBackup description:</h3>
<hr>
<TEXTAREA   STYLE="border:1px   dotted   #6CABE7;width: 800px;height: 200px;background-color:#CCCCCC;">
<%=command %>
</textarea> 
</form>

<!-- onlinedown -->
<form id="thisform" method="post" action="databasebackup" enctype="multipart/form-data">
	<hr>
	<table border="1" cellpadding="1" cellspacing="1">
		<tbody>
		<tr class="AttributesHeader">
			<th>No</th>
		    <th>Name</th>
		    <th>DATETIME</th>
		    <th>down</th>
		    <th>Description</th>
		</tr>

<%
for(int i=0;i<listnames.size();i++){
%>
		<tr style="">
			<td><%=i %></td>
		    <td><%=listnames.get(i)[0] %></td>
		    <td><%=listnames.get(i)[1] %></td>
		    <td style="width: 130px" align="center">
		    <a href="<%=basePath %>down?fileName=<%=listnames.get(i)[0] %>" mce_href="down?fileName=<%=listnames.get(i)[0] %> " >onlinedown</a>  
		    </td>
		    <td>Log zip file.</td>
		</tr>
<%
}
%>
	</tbody>
	</table>
</form>
</body></html>